{ "metadata": { "language": "Julia", "name": "", "signature": "sha256:94fa37b5577564aa4793a1cc812ed8efd58a7115e79eebf371ff84293e5b43af" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 4, "metadata": {}, "source": [ "Instructions: You may use any computer language you like, but if you are not using Julia, you will need to set things up yourself." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "a. Using the matrix squaring operator create a \"triangular\" matrix with 1 on the main diagonal, 2 above, etc.\n", "$M(n) = \\left( \\begin{array}{ccccc} 1 & 2 & \\ldots & n-1 & n\\\\ & 1 & 2 & \\ldots & n-1 \\\\ & & \\ddots & \\ddots \\\\ &&& 1 & 2 \\\\ &&&& 1\\end{array} \\right)$" ] }, { "cell_type": "code", "collapsed": false, "input": [ "M(n) = triu(ones(n,n))^2 \n", "M(5)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "{M(n) for n=1:6}" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "b. You very likely have heard of the triangular numbers: \n", "$$T_n = 1+2+\\ldots+n.$$" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#Here they are\n", "cumsum(1:10)'" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "heading", "level": 4, "metadata": {}, "source": [ "Don't use cumsum, or sum or \"+\", just matrix operations to create the matrix that has the triangular numbers on the diagonals:\n", "Explain roughly (not too formal a proof), why your idea works." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$M(n) = \\left( \\begin{array}{ccccc} 1 & 3 & \\ldots & (n-1)n/2 & n(n+1)/2\\\\ & 1 & 3 & \\ldots & (n-1)n/2 \\\\ & & \\ddots & \\ddots \\\\ &&& 1 & 3 \\\\ &&&& 1\\end{array} \\right)$" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "c. Don't stop. Keep going, and get the tetrahedral numbers. Explain briefly why this worked." ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 5 }, { "cell_type": "markdown", "metadata": {}, "source": [ "e) Let $A=\\left[\\begin{array}{c} 1\\\\ 2\\\\ 3\\\\ 1\\end{array}\\right]$ and $B=\\left[\\begin{array}{ccc} -1& 2& 1& 4\\end{array}\\right]$. Compute $(AB)^{10}$ by using Julia. Explain why it's possible to get this without a computer!" ] }, { "cell_type": "code", "collapsed": false, "input": [ "A=[1;2;3;1]" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 2, "text": [ "4-element Array{Int64,1}:\n", " 1\n", " 2\n", " 3\n", " 1" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "B=[-1 2 1 4]" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 3, "text": [ "1x4 Array{Int64,2}:\n", " -1 2 1 4" ] } ], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "(A*B)^10" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 8 }, { "cell_type": "code", "collapsed": false, "input": [ "B*A" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 4, "text": [ "1-element Array{Int64,1}:\n", " 10" ] } ], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }